#include "pch.h"
#include "seVisibleGameObject.h"

seVisibleGameObject::seVisibleGameObject()
{
	_isLoaded = false;
}

seVisibleGameObject::~seVisibleGameObject()
{
}

void seVisibleGameObject::Load(std::string filename)
{
	if(_image.LoadFromFile(filename) == false)
	{
		_filename = "";
		_isLoaded = false;
	}
	else
	{
		_filename = filename;
		_sprite.SetImage(_image);
		_isLoaded = true;
	}
}

void seVisibleGameObject::Draw(sf::RenderWindow &renderWindow)
{
	if(_isLoaded)
	{
		renderWindow.Draw(_sprite);
	}
}

void seVisibleGameObject::Update()
{
}


void seVisibleGameObject::SetPosition(float x, float y)
{
	if(_isLoaded)
	{
		_sprite.SetPosition(x,y);
	}
}

sf::Vector2f seVisibleGameObject::GetPosition() const
{
  if(_isLoaded)
  {
    return _sprite.GetPosition();
  }
  return sf::Vector2f();
}

sf::Sprite& seVisibleGameObject::GetSprite()
{
  return _sprite;
}

bool seVisibleGameObject::IsLoaded() const
{
  return _isLoaded;
}

float seVisibleGameObject::GetHeight() const
{
  return _sprite.GetSize().y;
}

float seVisibleGameObject::GetWidth() const
{
  return _sprite.GetSize().x;
}

sf::Rect<float> seVisibleGameObject::GetBoundingRect() const
{
  sf::Vector2f size = _sprite.GetSize();
  sf::Vector2f position = _sprite.GetPosition();

  return sf::Rect<float>(
            position.x - size.x/2,
            position.y - size.y/2,
            position.x + size.x/2,
            position.y + size.y/2
            );
}
